package com.touchportfolio.controller
{
	import com.touchportfolio.loadQueue.loaders.ImageLoader;
	import com.touchportfolio.model.ApplicationModel;
	import com.touchportfolio.view.Row;
	import com.touchportfolio.view.RowBasic;
	
	import flash.events.MouseEvent;
	import flash.geom.Point;

	public class MouseController
	{
		private var _appModel:ApplicationModel = ApplicationModel.getInstance();
		private var _row:RowBasic;
		
		public function MouseController(row:RowBasic)
		{
			_row = row;
			
			_row.addEventListener(MouseEvent.CLICK, onClickHandler);
			_row.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDownHandler);
			_row.addEventListener(MouseEvent.MOUSE_UP, onMouseUpHandler);
			_row._slideshowCloseBtn.addEventListener(MouseEvent.CLICK, onCloseClick);
			_row.addEventListener(MouseEvent.DOUBLE_CLICK, onDoubleClickHandler);
		}
		
		private function onClickHandler(e:MouseEvent):void
		{
			if(!_appModel.activeRowOpen && _appModel.activeRow == _row.node.rowId)
				_appModel.activeRowOpen = true;
			else if((_appModel.activeRow == _row.node.rowId) && _appModel.activeRowOpen) {  }//_appModel.activeRowOpen = false;
			else _appModel.activeRow = _row.node.rowId;
		}
		
		private function onCloseClick(e:MouseEvent):void
		{
			if(_appModel.activeRowOpen && _appModel.slideshowReady)
			{
				trace("[MOUSE] close button click");
				_appModel.activeRowOpen = false;	
			}
		}
		
		private function onMouseDownHandler(e:MouseEvent):void
		{
			if(!_appModel.activeRowOpen)
			_appModel.dragAttract = true;
			else if(_appModel.slideshowReady)
			{
				trace("[MOUSE] start drag");
				_appModel.slideshowDrag = true;
			}
		}
		
		private function onMouseUpHandler(e:MouseEvent):void
		{
			if(!_appModel.activeRowOpen)
			_appModel.dragAttract = false;
			else if(_appModel.slideshowReady)
			{
				trace("[MOUSE] end drag");
				_appModel.slideshowDrag = false;
			}
		}
		
		private function onDoubleClickHandler(e:MouseEvent):void
		{
			trace("[MOUSE] on double click handler");
			if((_appModel.activeRow == _row.node.rowId) && _appModel.activeRowOpen && _appModel.slideshowReady) 
			{ 
				_appModel.activeRowOpen = false;  
			}
		}
		
	}
}